<?php

namespace app\common\service;

use app\common\service\Base;
use app\common\model\Footprint as FootprintModel;

class Footprint extends Base {

     public function __construct() {
         parent::__construct();
         $this->currentModel = new FootprintModel();
     }

    /**
     * 获取我的足迹列表
     * @param $fromCustomerId
     * @param $timeSortType
     * @param $pageNum
     * @param $pageSize
     * @return array|\PDOStatement|string|\think\Collection
     */
     public function getFootprintListForPage($fromCustomerId,
                                             $timeSortType, $pageNum, $pageSize) {

         $map['f.from_customer_id'] = $fromCustomerId;
         $map['c.current_level'] = config('enum.customerCurrentLevel.store.value');

         return $this->currentModel->alias('f')
             ->field('c.nickname, c.headimgurl, c.history_point, c.background_image,
                    c.newest_like_json, f.update_time, c.id customer_id, c.total_point')
             ->join('__CUSTOMER__ c', 'f.to_customer_id = c.id')
             ->where($map)
             ->page($pageNum, $pageSize)
             ->order("f.update_time $timeSortType")
             ->select();

     }

     public function findByFromCustomerIdAndToCustomerId($fromCustomerId, $toCustomerId) {

         $map['from_customer_id'] = $fromCustomerId;
         $map['to_customer_id'] = $toCustomerId;

         return $this->currentModel
             ->where($map)
             ->find();
     }
}